<template>
	<div class="addTask">
		<Modal :mask-closable="false" v-model="create" title="生成领料任务" class="modal-content-layout" width="50%">
			<div class="content-item">
				<Row>
					<Col class="pd16">
						<Form ref="form" :disabled="disabled" class="formList" :model="formItem" label-position="top" :rules="ruleValidate">
							<Row :gutter="20">
								<Col span="12">
									<FormItem label="待领料数量">
										<InputNumber
											controls-outside
											type="number"
											v-model="formItem.quantityToPicked"
											disabled
											readonly
											style="width: 100%"
											:placeholder="`${$t('common.inputInfo')}`"
										>
											<span slot="append">%</span>
										</InputNumber>
									</FormItem>
								</Col>
								<Col span="12">
									<FormItem label="生成领料数量" prop="quantity">
										<InputNumber
											type="number"
											controls-outside
											v-model="formItem.quantity"
											:precision="2"
											style="width: 100%"
											:min="0"
											:active-change="false"
											:placeholder="`${$t('common.inputInfo')}`"
										>
											<span slot="append">%</span>
										</InputNumber>
										<!-- <Input
											type="number"
											v-model="formItem.moldingCycle"
											:min="0"
											@on-keyup="keyUp5($event, 'moldingCycle', true)"
											:max="999999"
											:placeholder="`${$t('common.inputInfo')}`"
										>
										</Input> -->
									</FormItem>
								</Col>
							</Row>
							<Row :gutter="20">
								<Col span="24">
									<FormItem label="备注" prop="remarks">
										<Input type="text" v-model="formItem.remarks" :placeholder="`${$t('common.inputInfo')}`" />
									</FormItem>
								</Col>
							</Row>
						</Form>
					</Col>
				</Row>
			</div>
			<div slot="footer">
				<Button type="default" @click="create = false">{{ $t('common.Cancle') }}</Button>
				<Button type="primary" v-if="!disabled" :loading="loading" @click="addOk('form')">{{ $t('maintenance.Confirmed') }}</Button>
			</div>
		</Modal>
	</div>
</template>
<script>
import { InputNumber } from 'view-design';
export default {
	name: 'addMold',
	components: { InputNumber },
	data() {
		return {
			create: false,
			disabled: false,
			formItem: {},
			addtitle: {},
			moldList: [],
			ruleValidate: {
				quantity: [{ required: true, message: '请输入利用率' }],
			},
		};
	},
	mounted() {},
	methods: {
		//增加或编辑
		createfaultCodeShowH(delIds) {
			this.disabled = false;
			this.$refs.form.resetFields();
			this.formItem = {
				quantityToPicked: delIds[0].quantityToPicked,
				quantity: 0,
				remarks: '',
				id: delIds[0].id,
			};
			this.create = true;
		},
		addOk(name) {
			this.$refs[name].validate((valid) => {
				if (!valid) {
					return;
				} else {
					this.loading = true;
					this.axios({
						url: '/dms/feedingPlan/generateRequisitionTask',
						method: 'post',
						data: this.formItem,
					}).then((res) => {
						this.loading = false;
						if (res.code === 200) {
							this.$Message.success(res.msg);
							this.$emit('changeNum');
							this.create = false;
						} else {
							this.$Message.warning({
								content: res.msg,
								duration: 6,
								closable: true,
							});
						}
					});
				}
			});
		},
		check(row) {
			this.disabled = true;
			this.addtitle = `${this.$t('common.Check')}`;
			this.formItem = JSON.parse(JSON.stringify(row));
			this.create = true;
		},
		//获取仓库
		keyUp(e, key, money) {
			// 如果是删除为空 则不处理
			if (!this.formItem[key]) {
				return (this.formItem[key] = '');
			}
			// 每次抬键处理,对应金额渲染两位小数||数字
			let num = '';
			if (money) {
				num = this.formItem[key].match(/^\d*(\.?\d{0,2})/g)[0];
			} else {
				num = this.formItem[key].replace(/^[^\d]+$/g, '').split('.')[0];
			}
			this.formItem[key] = `${num}`;
		},
		keyUp5(e, key, money) {
			if (!this.formItem[key]) {
				return (this.formItem[key] = '');
			}
			let num = '';
			if (money) {
				num = this.formItem[key].match(/^\d*(\.?\d{0,5})/g)[0];
			} else {
				num = this.formItem[key].replace(/^[^\d]+$/g, '').split('.')[0];
			}
			this.formItem[key] = `${num}`;
		},
	},
};
</script>
